package LeetcodeTest_twenty_three;
//121.买股票的最佳时机

public class maxProfit
{
    public static void main(String[] args)
    {
        int[] price={7,6,4,3,1};
        System.out.println(Solution.maxProfit(price));
    }
}
class Solution
{
    public static int maxProfit(int[] prices)
    {
        if(prices.length<2)
            return 0;
        int i;
        int minPrice=prices[0];
        int maxProfit=0;
        for(i=0;i<prices.length;i++)
        {
            minPrice=Math.min(minPrice,prices[i]);
            maxProfit=Math.max(maxProfit,prices[i]-minPrice);
        }
        return maxProfit;
    }
}